<?php
include('../../include/functions.inc.php');
include('../../include/inputbuilder.inc.php');
include('../../include/maintenance.inc.php');

if (isEmpty(getParam('CARNET'))) {
    echo 'WRONG PARAMETER';
} else {

    $mStudents = unserialize($_SESSION['mStudents']);

    $builder = new InputBuilder();
    $builder->db = $db;
    $tabs = $db->query_select('cllg_table_tab', "TABLE_NAME='cllg_student'");
    $rows = $db->query_select('cllg_student', sprintf("ID='%s'", getParam('CARNET')));
    $arrEmpresas = $db->query_select('cllg_empresa');
    
    if(!isEmpty($rows[0]['FK_EMPRESA'])){
    $emp = $db->query_select("cllg_empresa",  sprintf("ID='%s'",$rows[0]["FK_EMPRESA"]));
    
    }
  
    foreach ($rows as $row) {
        ?>
        <form id="<?php echo $mStudents->formName; ?>" name="<?php echo $mStudents->formName; ?>" method="POST" action="<?php echo $mStudents->updateUrlPage; ?>">
            <div id="panel" class="">
                <ul class="nav nav-tabs">
                    <?php
                    $ix = 0;
                    foreach ($tabs as $t) {
                        $ix++;
                        ?>
                        <li class="active" style="font-weight:bolder" tabindex="<?php echo $ix; ?>"><a><?php echo $t["CAPTION"]; ?></a></li>
                    <?php } ?>
                </ul>
                <div class="">
                    <?php
                    $ix = 0;
                    foreach ($tabs as $t) {
                        $ix++;
                        ?>
                        <div class="TabbedPanelsContent">
                            <table class=""  width="100%" border="0" cellspacing="0" cellpadding="0">
                                <tr>
                                    <th ><legend>DATOS ESTUDIANTE</legend></th>
                                <th >
                                <legend><div style="margin-left: 30%;margin-top: 1.4%" class="btn-group">
                                        <input type="button" name="cmdOk" class="btn btn-info"  id="cmdOk" value="Guardar" onClick="javascript:formOkBt($(this.form), updateAction);
                                                if (jQuery('#FOTO').val().length > 0) {
                                                    document.formFoto.submit();
                                                }
                                                jQuery('#cmAddcontainer').show(); 
                                                " />
                                        <input type="button" name="eliminar" id="eliminar" onclick="javascript:deleteAction('<?php echo $mStudents->deleteUrlPage; ?>',<?php echo $mStudents->getDeleteUrl(); ?>); jQuery('#cmAddcontainer').show();" value="Eliminar" class="btn btn-info" />        
                                        <input type="button" name="cmdCancel" id="cmdCancel" class="btn btn-info" value="Cancelar" onClick="loadTable(); jQuery('#cmAddcontainer').show();" />
                                    </div></legend>    
                                </th>
                                </tr>
                                <tr>
                                    <td colspan="2">
                                        <table width="100%" border="0" cellspacing="0" cellpadding="0">
                                            <?php
                                                if ($ix == 3) {
                                                ?>
                                                    <tr>
                                                        <td>EMPRESA</td>
                                                        <td colspan="2">
                                                            <select style="width:314px;" name="FK_EMPRESA" id="FK_EMPRESA">
                                                                <option value=""></option>
                                                                <?php
                                                                while( $arrTMP = each($arrEmpresas) ) {
                                                                    ?>
                                                                <option <?php echo (isset($emp) ? ($arrTMP['value']['ID'] == $emp[0]['ID'] ? "selected='selected'" : "") : ""); ?> value="<?php print $arrTMP['value']['ID']; ?>"><?php print $arrTMP['value']['NOMBRE']; ?></option>
                                                                    <?php
                                                                }
                                                                ?>
                                                            </select>
                                                            <a href="#infoEmp" style="margin-bottom:1.7%" role="button" class="btn btn-info" data-toggle="modal">Ver información</a>
                                                        </td>
                                                    </tr>
                                                <?php
                                                }
                                            if ($ix == 1) {
                                            ?>
                                                    
                                                    <tr>
                                                        <td width="">* NOMBRES</td>
                                                        <td width="">
                                                            <input name="FIRST_NAME" type="text" id="FIRST_NAME" value="<?php echo $row['FIRST_NAME']; ?>" size="30" maxlength="100" />
                                                            -
                                                            <input name="SECOND_NAME" type="text" value="<?php echo $row['SECOND_NAME']; ?>" id="SECOND_NAME" size="30" maxlength="100" />
                                                        </td>
                                                        <td>APELLIDOS</td>
                                                        <td>
                                                            <input name="LAST_NAME"  type="text" id="LAST_NAME" value="<?php echo $row['LAST_NAME']; ?>" size="60" maxlength="100" />
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td>* NO. CARNET</td>
                                                        <td><input name="ID" type="text" value="<?php echo getParam('CARNET'); ?>" id="ID" /></td>
                                                        <td>AIU CODE</td>
                                                        <td>
                                                            <input name="AIU_CODE" type="text" value="<?php echo $row['AIU_CODE']; ?>" id="AIU_CODE" />
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td>FECHA DE NACIMIENTO</td>
                                                        <td>          
                                                            <input name="BIRTH_DATE" readonly="readonly"  type="text" id="BIRTH_DATE" value="<?php echo $row['BIRTHDATE']; ?>" />
                                                            <input name="STATUS" type="hidden" id="STATUS" value="<?php echo $row['STATUS']; ?>" />
                                                        </td>
                                                        <td>SEXO</td>
                                                        <td>
                                                            <select name="GENDER" size="1" id="GENDER">
                                                                <option value="M" <?php print $row['GENDER'] == "M" ? 'selected="selected"' : ''; ?>>Masculino</option>
                                                                <option value="F" <?php print $row['GENDER'] == "F" ? 'selected="selected"' : ''; ?>>Femenino</option>
                                                            </select>
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td>EDAD</td>
                                                        <td>
                                                            <h3>
                                                                <div id="edad">
                                                                    <?php $cYear = date('Y'); ?>
                                                                    <?php print $cYear - date('Y', strtotime($row['BIRTHDATE'])); ?>
                                                                    &nbsp;A&ntilde;os
                                                                </div>
                                                            </h3>
                                                        </td>
                                                        <td>FOTO</td>
                                                        <td>
                                                            <a id="aFoto" href="#" onclick="javascript: document.formFoto.FOTO.click();">Seleccionar</a>&nbsp;<div id="divFoto"></div>
                                                            <?php
                                                            $strPath = '../../img/logocinde.png';
                                                            if (!empty($row['PICTURE_PATH'])) {
                                                                $strPath = '../../' . $row['PICTURE_PATH'];
                                                            }
                                                            ?>
                                                            <img src="<?php print $strPath; ?>" width="100px" height="100px" alt="">
                                                        </td>
                                                    </tr>
                                                    <?php
                                                }
                                                $builder->build("cllg_student", getParam('CARNET'), $t['ID']);
                                                ?>
                                            </table>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td colspan="2">&nbsp;</td>
                                    </tr>
                                </table>
                            </div>
                            <?php
                        }
                        ?> 
                    </div>
                </div>
            </form>
            <form id="formFoto" name="formFoto" method="post" target="ifmFoto" action="<?php echo $mStudents->saveNewUrlPage; ?>" enctype="multipart/form-data">
                <input type="hidden" name="operation" value="sf" readonly="readonly"/>
                <input type="hidden" name="ID" id="ID" value="<?php print getParam('CARNET'); ?>" readonly="readonly"/>
                <input type="file" name="FOTO" id="FOTO" style="display: none;" onchange="javascript: jQuery('#divFoto').html(jQuery('#FOTO').val());" />
            </form>
            <iframe name="ifmFoto" style="display: none;"></iframe>
            <!-- INFORMACIÓN DE LA EMPRESA-->
            <div id="infoEmp" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                <div class="modal-header">
                    <h3 id="myModalLabel"><?php echo (isset($emp) ? strtoupper($emp[0]['NOMBRE']) : "&nbsp;" ); ?></h3>
                </div>
                <div class="modal-body">
                    <p>
                        <table width="75%" style="text-align: right">
                            <?php 
                            if (isset($emp)){
                                $emp = $emp[0];
                                echo "<tr>
                                        <td>CORPORACIÓN: </td>
                                        <td>". $emp['CORPORACION'] ."</td>
                                      </tr>
                                      <tr>
                                        <td>NOMBRE: </td>
                                        <td>". $emp['NOMBRE'] ."</td>
                                      </tr>
                                      <tr>
                                        <td>DIRECCIÓN: </td>
                                        <td>". $emp['DIRECCION'] ."</td>
                                      </tr>
                                      <tr>
                                        <td>WEB: </td>
                                        <td>". $emp['WEB'] ."</td>
                                      </tr>
                                      <tr>
                                        <td>PBX: </td>
                                        <td>". $emp['PBX'] ."</td>
                                      </tr>
                                      <tr>
                                        <td>OBSERVACIÓN: </td>
                                        <td>". $emp['OBSERVACION'] ."</td>
                                      </tr>";
                            }else{
                                echo "<tr>
                                        <td>El alumno no se ha asignado a ninguna empresa!!</td>
                                      </tr>";
                            }
                            ?>
                        </table>
                    </p>
                </div>
                <div class="modal-footer">
                    <button class="btn btn-info" data-dismiss="modal" aria-hidden="true">Cerrar</button>
                </div>
            </div>
            <?php
        }
        $_SESSION['fields'] = serialize($builder->fieldsArray);
    }

?>